﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
#if !NETCOREAPP
using System.Web;
using System.Web.Mvc;
using System.Web.WebPages;
    using System.Web.Mvc.Html;

#endif

#if NETCOREAPP
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.AspNetCore.Mvc.Rendering;
using Kugar.Core.Web;
#endif
using Kugar.MVC.MobileUI.WeUI.Helpers;

namespace Kugar.MVC.MobileUI.WeUI.PageControls.PageCommons
{
    public class PageCommon_PopupContainer:ContainerBase
    {
        private string _title = "";
        private PopupShowSide _side = PopupShowSide.BottomToTop;

        public PageCommon_PopupContainer(ViewContext viewContext) : base(viewContext)
        {
            this.Css("weui-popup__container popup-bottom");
        }

        public PageCommon_PopupContainer Title(string title)
        {
            _title = title;

            return this;
        }
        
        public PageCommon_PopupContainer ShowSide(PopupShowSide side = PopupShowSide.BottomToTop)
        {
            _side = side;

            return this;
        }

        public override void Dispose()
        {

            ViewContext.Writer.WriteLine("</div> <!-- end  modal-content -->");

            ViewContext.Writer.WriteLine("</div> <!-- end popup__modal -->");

            ViewContext.Writer.WriteLine("</div> <!-- end popup__container -->");
        }
        
        internal override ContainerBase RenderInternal()
        {
            var sideCss = "";

            if (_side!= PopupShowSide.BottomToTop)
            {
                switch (_side)
                {
                    case PopupShowSide.TopToBottom:
                        sideCss = "fromTop";
                        break;
                    case PopupShowSide.LeftToRight:
                        sideCss = "fromLeft";
                        break;
                    case PopupShowSide.RightToLeft:
                        sideCss = "fromRight";
                        break;
                }

                this.Css(sideCss);
            }

            ViewContext.Writer.WriteLine($"<div {_attrs}>");
            ViewContext.Writer.WriteLine("<div class=\"weui-popup__overlay\"></div>");
            ViewContext.Writer.WriteLine("<div class=\"weui-popup__modal\">");

            if (!string.IsNullOrWhiteSpace(_title))
            {
                ViewContext.Writer.WriteLine($"<div class=\"toolbar\"><div class=\"toolbar-inner\"><a href=\"javascript:;\" class=\"picker-button close-popup\">关闭</a><h1 class=\"title\">{_title}</h1></div></div>");
            }

            ViewContext.Writer.WriteLine("<div class=\"modal-content\">");
            
            return this;
        }
    }

    public enum PopupShowSide
    {
        TopToBottom,
        BottomToTop,
        LeftToRight,
        RightToLeft
    }
}